package com.zyj.springboothapim.controller;

import com.zyj.springboothapim.bean.Admin;
import com.zyj.springboothapim.bean.User;
import com.zyj.springboothapim.service.AdminService;
import com.zyj.springboothapim.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
//这个是默认json接收和发送@RestController
@RequestMapping("/User")
public class UserController {
    UserService userService;

    @Autowired
    public void setUserService(UserService userService)
    {
        this.userService = userService;
    }

    //查询所有用户
    @RequestMapping(value = "/selectUser" ,method = {RequestMethod.POST,RequestMethod.GET})
    @ResponseBody
    public List<User> selectAdmin(){
        System.out.println("/User/selectUser");
        return userService.selectUser();
    }

    //添加用户
    @RequestMapping(value = "/insertUser",method = RequestMethod.POST)
    @ResponseBody
    public String insertUser(@RequestBody User user)
    {
        userService.insertUser(user);
        return "insert success";
    }

    //通过user_id修改user_table表
    @RequestMapping(value = "/updatatUser",method = RequestMethod.POST)
    @ResponseBody
    public String updataUser(@RequestBody User user)
    {
        userService.updateUser(user);
        return "updata success";
    }
}
